<?php

namespace Frieza\Modules\BasicCheck\Actions;

use Doraemon\model\BasicCheck\CheckNick;
use Doraemon\service\BasicCheck\CheckCommonInfo;
use Doraemon\service\BasicCheck\CheckNickInfo;
use Illuminate\Http\Request;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;

class NickApproved extends RowAction
{
    public $name = '审核通过';
    const TOAST_ALERT = '你确定要忽略此用户吗？';

    public function handle($id)
    {
        $adminId = Admin::user()->id;

        $data = [
            'check_time' => time(),
            'admin_id' => $adminId,
            'check_status' =>CheckCommonInfo::CHECK_STATUS_YES,
        ];
        $res = CheckNickInfo::updateInfo(['id' => $id],$data);
        if ($res) {
            return $this->response()->success('审核成功')->refresh();
        } else {
            return $this->response()->error('操作失败,稍后重试!');
        }


    }

    public function retrieveModel(Request $request)
    {
        if (!$key = $request->get('_key')) {
            return false;
        }

        return $key;
    }

    public function dialog()
    {
        $this->confirm(self::TOAST_ALERT);
    }

}